home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte20
/
ex9.c
< prev
Wrap
C/C++ Source or Header
|
1995-03-22
|
5KB
|
105 lines
#include <genstub.c>
#define EDIT_ID 1000 // Identifies the child window.
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CREATE: // Create ab edit child window to show section keys.
{
RECT rectClient;
HWND hWndEdit;
LRESULT lRetVal = DefWindowProc(hWnd, uMsg, wParam, lParam);
GetClientRect( hWnd, &rectClient ); // Use client rectangle to center child.
hWndEdit = CreateWindow( "edit", // class name
"", // window name
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL, // style
10, 10, // location
rectClient.right - rectClient.left - 20, // width
rectClient.bottom - rectClient.top - 20, // height
hWnd, // parent
(HMENU) EDIT_ID, // child window ID
hInst, // app instance
NULL ); // special parameters
if ( hWndEdit )
{
LPTSTR lpIniValuesBuffer = HeapAlloc( GetProcessHeap(),
HEAP_ZERO_MEMORY,
0x1000 );
LPTSTR lpEditBuffer = HeapAlloc( GetProcessHeap(),
HEAP_ZERO_MEMORY,
0x1000 );
LPTSTR lpTempInput = lpIniValuesBuffer;
LPTSTR lpTempOutput = lpEditBuffer;
GetProfileSection( "Desktop", // section name
lpIniValuesBuffer, // buffer
0x1000 ); // buffer size
// Format for output to edit box. Add CR/LF after every line.
while (*lpTempInput)
{
wsprintf(lpTempOutput, "%s\r\n", lpTempInput);
lpTempInput += (lstrlen(lpTempInput) + 1);
lpTempOutput += lstrlen(lpTempOutput);
}
SendMessage( hWndEdit, WM_SETTEXT, 0,(LPARAM) lpEditBuffer );
HeapFree( GetProcessHeap(), 0L, lpIniValuesBuffer );
HeapFree( GetProcessHeap(), 0L, lpEditBuffer );
}
return lRetVal;
}
case WM_COMMAND: // process menu items
switch ( LOWORD( wParam ) )
{
case IDM_TEST:
{
LPTSTR lpTemp;
HWND hWndEdit = GetDlgItem( hWnd, EDIT_ID );
if ( hWndEdit )
{
int iItem;
LPTSTR lpIniValuesBuffer = HeapAlloc( GetProcessHeap(),
HEAP_ZERO_MEMORY,
0x1000 );
LPTSTR lpTemp = lpIniValuesBuffer;
SendMessage(hWndEdit, WM_GETTEXT, 0xfff,(LPARAM) lpTemp);
// Format for output to section.
while (*lpTemp)
{
if (*lpTemp == '\r')
*lpTemp = ' ';
if (*lpTemp == '\n')
*lpTemp = 0;
lpTemp++;
}
WriteProfileSection( "Desktop", // section name
lpIniValuesBuffer ); // buffer
HeapFree( GetProcessHeap(), 0L, lpIniValuesBuffer );
}
}
break;
case IDM_EXIT: // remove TestSection from WIN.INI if it exists.
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return( 0L ) ;
}
#include <about.c>